//
//  Style7TableViewCell.m
//  PiPiPineapple
//
//  Created by 李晓东 on 17/11/7.
//  Copyright © 2017年 PeanutXu. All rights reserved.
//

#import "Style7TableViewCell.h"
#import "Tools.h"
#import "UIImage+Category.h"

@interface Style7TableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *redBallsView;
@property (weak, nonatomic) IBOutlet UILabel *blueBallView;
@property (weak, nonatomic) IBOutlet UILabel *acView;
@property (weak, nonatomic) IBOutlet UILabel *resultView;

@end

@implementation Style7TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)showData:(DoubleChromosphere *)doubleChromosphere{
    NSArray *redBallsArray = doubleChromosphere.returnRedBall;
    NSString *acValueStr = doubleChromosphere.returnACValue;
    NSArray *nextSomeBody = doubleChromosphere.returnNextSomeBody;
    
    NSString *redBallsStr = [redBallsArray componentsJoinedByString:@" "];
    NSString *someBody = doubleChromosphere.returnSomebody;
    
    if (someBody != nil) {
        // 获取 somebody 所在的位置,设置 attributeString 的 color
        NSRange someBodyInBalls = [redBallsStr rangeOfString:someBody];
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:redBallsStr];
        [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:someBodyInBalls];
        [attrStr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:someBodyInBalls];
        _redBallsView.attributedText = attrStr;
    } else {
        _redBallsView.text = [redBallsArray componentsJoinedByString:@" "];
    }
    
    _blueBallView.text = doubleChromosphere.returnBlueBall;
    _acView.text = acValueStr;
    
    NSMutableAttributedString *resultAttrStr = [[NSMutableAttributedString alloc]init];
    CGSize resultViewStrSize = _resultView.intrinsicContentSize;
    NSTextAttachment *attach = [[NSTextAttachment alloc]init];
    UIImage *newImage = [[UIImage imageNamed:@"arror_yellow"]imageRotateOfRadians:0];
    [attach setImage:newImage];

    [attach setBounds:CGRectMake(0, -3, resultViewStrSize.height, resultViewStrSize.height)];
    
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach];

    
    [resultAttrStr insertAttributedString:string atIndex:0];
    [resultAttrStr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
    [resultAttrStr appendAttributedString:[[NSAttributedString alloc]initWithString:[nextSomeBody componentsJoinedByString:@" "]]];
    [resultAttrStr addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0f / 255.0f green:112.0f / 255.0f blue:124.0f / 255.0f alpha:1]} range:NSMakeRange(2, [nextSomeBody componentsJoinedByString:@" "].length)];
    _resultView.attributedText = resultAttrStr;
    
}

@end
